home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 February (DVD) / PCWorld_2008-02_DVD.iso / v cisle / PHP / PHP.exe / EasyPHP-2.0b1-setup.exe / {app} / phpmyadmin / libraries / Theme.class.php < prev    next >
Encoding:
PHP Script  |  2006-11-18  |  6.9 KB  |  307 lines

  1. <?php
  2. /* $Id: Theme.class.php 8960 2006-04-26 17:09:45Z cybot_tm $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5. class PMA_Theme {
  6.     /**
  7.      * @var string version
  8.      */
  9.     var $version = '0.0.0.0';
  10.  
  11.     /**
  12.      * @var string name
  13.      */
  14.     var $name = '';
  15.  
  16.     /**
  17.      * @var string id
  18.      */
  19.     var $id = '';
  20.  
  21.     /**
  22.      * @var string
  23.      */
  24.     var $path = '';
  25.  
  26.     /**
  27.      * @var string
  28.      */
  29.     var $img_path = '';
  30.  
  31.     /**
  32.      * @var array   valid css types
  33.      */
  34.     var $types = array('left', 'right', 'print');
  35.  
  36.     /**
  37.      * @var integer last modification time for info file
  38.      */
  39.     var $mtime_info = 0;
  40.  
  41.     function __wakeup()
  42.     {
  43.         $this->loadInfo();
  44.         $this->checkImgPath();
  45.     }
  46.  
  47.     function loadInfo()
  48.     {
  49.         if (! file_exists($this->getPath() . '/info.inc.php')) {
  50.             return false;
  51.         }
  52.  
  53.         if ($this->mtime_info === filemtime($this->getPath() . '/info.inc.php')) {
  54.             return true;
  55.         }
  56.  
  57.         @include $this->getPath() . '/info.inc.php';
  58.  
  59.         // did it set correctly?
  60.         if (! isset($theme_name)) {
  61.             return false;
  62.         }
  63.  
  64.         $this->mtime_info = filemtime($this->getPath() . '/info.inc.php');
  65.  
  66.         if (isset($theme_full_version)) {
  67.             $this->setVersion($theme_full_version);
  68.         } elseif (isset($theme_generation, $theme_version)) {
  69.             $this->setVersion($theme_generation . '.' . $theme_version);
  70.         }
  71.         $this->setName($theme_name);
  72.  
  73.         return true;
  74.     }
  75.  
  76.     /**
  77.      * returns theme object loaded from given folder
  78.      * or false if theme is invalid
  79.      *
  80.      * @static
  81.      * @param   string  path to theme
  82.      * @return  object  PMA_Theme
  83.      */
  84.     function load($folder)
  85.     {
  86.  
  87.         $theme = new PMA_Theme();
  88.  
  89.         $theme->setPath($folder);
  90.  
  91.         if (! $theme->loadInfo()) {
  92.             return false;
  93.         }
  94.  
  95.         $theme->checkImgPath();
  96.  
  97.         return $theme;
  98.     }
  99.  
  100.     function checkImgPath()
  101.     {
  102.         if (is_dir($this->getPath() . '/img/')) {
  103.             $this->setImgPath($this->getPath() . '/img/');
  104.             return true;
  105.         } elseif (is_dir($GLOBALS['cfg']['ThemePath'] . '/original/img/')) {
  106.             $this->setImgPath($GLOBALS['cfg']['ThemePath'] . '/original/img/');
  107.             return true;
  108.         } else {
  109.             $GLOBALS['PMA_errors'][] =
  110.                 sprintf($GLOBALS['strThemeNoValidImgPath'], $this->getName());
  111.             trigger_error(
  112.                 sprintf($GLOBALS['strThemeNoValidImgPath'], $this->getName()),
  113.                 E_USER_WARNING);
  114.             return false;
  115.         }
  116.     }
  117.  
  118.     /**
  119.      * returns path to theme
  120.      * @uses    $this->$path    as return value
  121.      * @return  string  $path   path to theme
  122.      */
  123.     function getPath()
  124.     {
  125.         return $this->path;
  126.     }
  127.  
  128.     /**
  129.      * returns layout file
  130.      *
  131.      * @return  string  layout file
  132.      */
  133.     function getLayoutFile()
  134.     {
  135.         return $this->getPath() . '/layout.inc.php';
  136.     }
  137.  
  138.     /**
  139.      * set path to theme
  140.      * @uses    $this->$path    to set it
  141.      * @param   string  $path   path to theme
  142.      */
  143.     function setPath($path)
  144.     {
  145.         $this->path = trim($path);
  146.     }
  147.  
  148.     /**
  149.      * sets version
  150.      * @uses    $this->version
  151.      * @param   string new version
  152.      */
  153.     function setVersion($version)
  154.     {
  155.         $this->version = trim($version);
  156.     }
  157.  
  158.     /**
  159.      * returns version
  160.      * @uses    $this->version
  161.      * @return  string  version
  162.      */
  163.     function getVersion()
  164.     {
  165.         return $this->version;
  166.     }
  167.  
  168.     /**
  169.      * checks theme version agaisnt $version
  170.      * returns true if theme version is equal or higher to $version
  171.      *
  172.      * @uses    version_compare()
  173.      * @uses    $this->getVersion()
  174.      * @param   string  $version    version to compare to
  175.      * @return  boolean
  176.      */
  177.     function checkVersion($version)
  178.     {
  179.         return version_compare($this->getVersion(), $version, 'lt');
  180.     }
  181.  
  182.     /**
  183.      * sets name
  184.      * @param   string  $name   new name
  185.      */
  186.     function setName($name)
  187.     {
  188.         $this->name = trim($name);
  189.     }
  190.  
  191.     /**
  192.      * returns name
  193.      * @return  string name
  194.      */
  195.     function getName()
  196.     {
  197.         return $this->name;
  198.     }
  199.  
  200.     /**
  201.      * sets id
  202.      * @param   string  $id   new id
  203.      */
  204.     function setId($id)
  205.     {
  206.         $this->id = trim($id);
  207.     }
  208.  
  209.     /**
  210.      * returns id
  211.      * @return  string id
  212.      */
  213.     function getId()
  214.     {
  215.         return $this->id;
  216.     }
  217.  
  218.     function setImgPath($path)
  219.     {
  220.         $this->img_path = $path;
  221.     }
  222.  
  223.     function getImgPath()
  224.     {
  225.         return $this->img_path;
  226.     }
  227.  
  228.     /**
  229.      * load css (send to stdout, normaly the browser)
  230.      *
  231.      * @uses    $this->getPath()
  232.      * @uses    $this->types
  233.      * @uses    PMA_SQP_buildCssData()
  234.      * @uses    file_exists()
  235.      * @uses    in_array()
  236.      * @param   string  $type   left, right or print
  237.      */
  238.     function loadCss(&$type)
  239.     {
  240.         if (empty($type) || ! in_array($type, $this->types)) {
  241.             $type = 'left';
  242.         }
  243.  
  244.         if ($type == 'right') {
  245.             echo PMA_SQP_buildCssData();
  246.         }
  247.  
  248.         $_css_file = $this->getPath()
  249.                    . '/css/theme_' . $type . '.css.php';
  250.  
  251.         if (! file_exists($_css_file)) {
  252.             return false;
  253.         }
  254.  
  255.         if ($GLOBALS['text_dir'] === 'ltr') {
  256.             $right = 'right';
  257.             $left = 'left';
  258.         } else {
  259.             $right = 'left';
  260.             $left = 'right';
  261.         }
  262.  
  263.         include $_css_file;
  264.         return true;
  265.     }
  266.  
  267.     /**
  268.      * prints out the preview for this theme
  269.      *
  270.      * @uses    $this->getName()
  271.      * @uses    $this->getVersion()
  272.      * @uses    $this->getId()
  273.      * @uses    $this->getPath()
  274.      * @uses    $GLOBALS['strThemeNoPreviewAvailable']
  275.      * @uses    $GLOBALS['strTakeIt']
  276.      * @uses    PMA_generate_common_url()
  277.      * @uses    addslashes()
  278.      * @uses    file_exists()
  279.      * @uses    htmlspecialchars()
  280.      */
  281.     function printPreview()
  282.     {
  283.         echo '<div class="theme_preview">';
  284.         echo '<h2>' . htmlspecialchars($this->getName())
  285.             .' (' . htmlspecialchars($this->getVersion()) . ')</h2>'
  286.             .'<p>'
  287.             .'<a target="_top" href="index.php'
  288.             .PMA_generate_common_url(array('set_theme' => $this->getId())) . '"'
  289.             .' onclick="takeThis(\'' . addslashes($this->getId()) . '\');'
  290.             .' return false;">';
  291.         if (@file_exists($this->getPath() . '/screen.png')) {
  292.             // if screen exists then output
  293.  
  294.             echo '<img src="' . $this->getPath() . '/screen.png" border="1"'
  295.                 .' alt="' . htmlspecialchars($this->getName()) . '"'
  296.                 .' title="' . htmlspecialchars($this->getName()) . '" /><br />';
  297.         } else {
  298.             echo $GLOBALS['strThemeNoPreviewAvailable'];
  299.         }
  300.  
  301.         echo '[ <strong>' . $GLOBALS['strTakeIt'] . '</strong> ]</a>'
  302.             .'</p>'
  303.             .'</div>';
  304.     }
  305. }
  306.  
  307. ?>